//
//  PopRecomViewController.m
//  SG
//
//  Created by FISH on 2018/4/20.
//  Copyright © 2018年 yimindai. All rights reserved.
//

#import "PopRecomViewController.h"

@interface PopRecomViewController ()

@end

@implementation PopRecomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _btnArray = [NSMutableArray array];

    _selectBtnArray = [NSMutableArray array];
    
    self.navigationController.navigationBarHidden = YES;

    [self createPopRecomViewControllerUI];
}

- (void)createPopRecomViewControllerUI
{
    [self createScrollViewUI];

    _loginBtn.frame = CGRectMake(0, kScreenHeight-kRealValue(50), kScreenWidth, kRealValue(50));
    _loginBtn.titleLabel.font = FONTTHRE;
    [_loginBtn addTarget:self action:@selector(toSelectLogin) forControlEvents:UIControlEventTouchUpInside];
}

- (void)createScrollViewUI
{
    _scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight-kRealValue(50));
    _imgView.frame = CGRectMake(0, 0, kScreenWidth, kRealValue(200));
    
    _mainView.frame = CGRectMake(0, _imgView.frame.size.height+20, kScreenWidth, _scrollView.frame.size.height- _imgView.frame.size.height-20);
    _topView.frame = CGRectMake(0, 0, kScreenWidth, 31);
    _topViewLab.frame = CGRectMake((kScreenWidth-100)/2, 5, 100, 21);
    _topViewLab.font = FONTTHRE;
    _topViewLeft.frame = CGRectMake(10, 10, (kScreenWidth-120)/2, 1);
    _topViewRight.frame = CGRectMake(_topViewLab.frame.origin.x+_topViewLab.frame.size.width, 10, (kScreenWidth-120)/2, 1);
    
    [self createBtmViewUI];
}

- (void)createBtmViewUI
{
    int BtmViewY = _topView.frame.size.height +_mainView.frame.origin.y;
    NSMutableArray *mutableArray = [NSMutableArray array];
    for(int tag=0;tag<33;tag++)
    {
        NSString *str = [NSString stringWithFormat:@"数据%d",tag];
        [mutableArray addObject:str];
    }
    int x = 0;
    int y = 0;
    for(int j=0;j<mutableArray.count;j++)
    {
        UIButton *Btn = [[UIButton alloc]initWithFrame:CGRectMake(((kScreenWidth-40-kRealValue(64)*3)/2+kRealValue(64))*x+20, BtmViewY+kRealValue(50)*y, kRealValue(64), kRealValue(40))];
        Btn.backgroundColor = KRedColor;
        Btn.tag = 1000+j;
        Btn.titleLabel.font = FONTONE;
        [Btn setTitle:StringFormat(@"%@",mutableArray[j]) forState:UIControlStateNormal];
        [Btn setTitleColor:KLightGrayColor forState:UIControlStateNormal];
        x++;
        if(x%3==0)
        {
            y++;
            x=0;
        }
        [Btn addTarget:self action:@selector(toSelectInterface:) forControlEvents:UIControlEventTouchUpInside];
        [_scrollView addSubview:Btn];
        [_btnArray addObject:Btn];
        _scrollContentH = Btn.frame.origin.y+Btn.frame.size.height;
    }
    _scrollView.contentSize = CGSizeMake(kScreenWidth, _scrollContentH);
}

- (void)toSelectInterface:(UIButton*)sender
{
    for(int i=0;i<_btnArray.count;i++)
    {
        UIButton *btn = _btnArray[i];
        if (btn.tag == sender.tag) {
            if(_selectBtnArray.count!=0){
                _bChecked = NO;
                for(int j=0;j<_selectBtnArray.count;j++)
                {
                    UIButton *sbtn = _selectBtnArray[j];
                    if([sbtn.titleLabel.text isEqualToString:btn.titleLabel.text]){
                        _bChecked = YES;
                    }
                }
                if(_bChecked == YES){
                    DLog(@"重复");
                    btn.backgroundColor = KRedColor;
                    [_selectBtnArray removeObject:btn];
                }
                else{
                    DLog(@"选中");
                    btn.backgroundColor = KGreenColor;
                    [_selectBtnArray addObject:btn];
                }
            }
            else{
                btn.backgroundColor = KGreenColor;
                [_selectBtnArray addObject:btn];
            }
        }
    }
}

- (void)toSelectLogin
{
    if(_selectBtnArray.count >=3)
    {
        DLog(@"一键发布");
        SGTabBarController *SGTabBar = [[SGTabBarController alloc]init];
        [AppDelegate shareAppDelegate].window.rootViewController = SGTabBar;
        [ [AppDelegate shareAppDelegate].window makeKeyAndVisible];
    }
    else
    {
        [MBProgressHUD showSuccessMessage:@"选择3个技能，money多多喔"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
